package com.jinzhi.jzweb.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.api.exception.IFastApiException;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.common.type.ApiEnumError;
import com.jinzhi.common.utils.Result;
import com.jinzhi.jzweb.domain.TrackDrawDO;
import com.jinzhi.jzweb.pojo.TrackDrawJiangXiVO;
import com.jinzhi.jzweb.pojo.TrackDrawRegularVO;
import com.jinzhi.jzweb.service.TrackDrawYuLinService;
import com.jinzhi.jzweb.utils.EasyPoiUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 
 * <pre>
 * 赛道抽签表（存储抽签信息）
 * </pre>
 * <small> 2024-02-28 09:32:18 | lance</small>
 */
@Controller
@RequestMapping("/jzweb/trackDrawYuLin")
public class TrackDrawYuLinController extends BaseController {

    @Autowired
    private TrackDrawYuLinService trackDrawYuLinService;


    /**
     * 抽签接口
     * @param trackDrawDTO
     * @return
     */
    @ResponseBody
    @GetMapping("/list")
    public Result<List<TrackDrawDO>> list(TrackDrawDO trackDrawDTO){

        return trackDrawYuLinService.trackDrawList(trackDrawDTO);
    }

    /**
     * 查询上次的抽签结果
     */
    @ResponseBody
    @GetMapping("/trackList")
    public Result<TrackDrawDO> trackList(TrackDrawDO trackDrawDTO){

        return trackDrawYuLinService.trackList(trackDrawDTO);
    }

    /**
     * 导出抽签结果信息
     *
     * @param response
     */
    @Log("导出抽签结果信息")
    @RequestMapping("/downloadImportTemplate")
    @ResponseBody
    public void downloadImportTemplate(HttpServletRequest request, HttpServletResponse response, TrackDrawDO trackDrawDTO) {
        Wrapper<TrackDrawDO> wrapper = new EntityWrapper<>();
        wrapper.orderBy(true,"sort");
        List<TrackDrawDO> trackDrawDOS = trackDrawYuLinService.selectList(wrapper);
        if (trackDrawDOS != null && trackDrawDOS.size() > 0) {
            //导出操作
            EasyPoiUtil.exportExcel(trackDrawDOS, "模块B综合实操技能抽签信息导出", "模块B综合实操技能抽签信息导出", TrackDrawDO.class,  "模块B综合实操技能抽签信息导出", response);
        } else {
            throw new IFastApiException(ApiEnumError.NOTBATCHSTU.getCodeStr());
        }
    }

    /**
     * 查询选手检录号 上次抽签结果
     */
    @ResponseBody
    @GetMapping("/trackStuList")
    public Result<TrackDrawDO> trackStuList(TrackDrawDO trackDrawDTO){

        return trackDrawYuLinService.trackStuList(trackDrawDTO);
    }


    /**
     * 抽签接口
     * @param trackDrawDTO
     * @return
     */
    @ResponseBody
    @GetMapping("/listStu")
    public Result<List<TrackDrawDO>> listStu(TrackDrawDO trackDrawDTO){

        return trackDrawYuLinService.trackDrawStuList(trackDrawDTO);
    }


    /**
     * 导出抽签结果信息
     *
     * @param response
     */
    @Log("导出抽签结果信息")
    @RequestMapping("/downloadImportTemplateStu")
    @ResponseBody
    public void downloadImportTemplateStu(HttpServletRequest request, HttpServletResponse response, TrackDrawDO trackDrawDTO) {
        Wrapper<TrackDrawDO> wrapper = new EntityWrapper<>();
        wrapper.orderBy(true,"sort");
        List<TrackDrawDO> trackDrawDOS = trackDrawYuLinService.selectList(wrapper);
        if (trackDrawDOS != null && !trackDrawDOS.isEmpty()) {
            List<TrackDrawRegularVO> trackDrawRegularVOS = new ArrayList<>();
            for (TrackDrawDO trackDrawDO : trackDrawDOS) {
                TrackDrawRegularVO trackDrawRegularVO = new TrackDrawRegularVO();
                BeanUtils.copyProperties(trackDrawDO,trackDrawRegularVO);
                trackDrawRegularVOS.add(trackDrawRegularVO);
            }
            //导出操作
            EasyPoiUtil.exportExcel(trackDrawRegularVOS, "模块C职业素养测试抽签信息导出", "模块C职业素养测试抽签信息导出", TrackDrawRegularVO.class,  "模块C职业素养测试抽签信息导出", response);
        } else {
            throw new IFastApiException(ApiEnumError.NOTBATCHSTU.getCodeStr());
        }
    }

    /**
     * 模块A制定照护计划检录号抽签
     * @param trackDrawDTO
     * @return
     */
    @ResponseBody
    @GetMapping("/listSch")
    public Result<List<TrackDrawDO>> trackDrawSchList(TrackDrawDO trackDrawDTO){

        return trackDrawYuLinService.trackDrawSchList(trackDrawDTO);
    }

    /**
     * 模块A制定照护计划检录号抽签 查询上一次抽签接口
     */
    @ResponseBody
    @GetMapping("/trackSchList")
    public Result<TrackDrawDO> trackSchList(TrackDrawDO trackDrawDTO){

        return trackDrawYuLinService.trackSchList(trackDrawDTO);
    }


    /**
     * 导出抽签结果信息
     *
     * @param response
     */
    @Log("导出抽签结果信息")
    @RequestMapping("/downloadImportTemplateSch")
    @ResponseBody
    public void downloadImportTemplateSch(HttpServletRequest request, HttpServletResponse response, TrackDrawDO trackDrawDTO) {
        Wrapper<TrackDrawDO> wrapper = new EntityWrapper<>();
        wrapper.orderBy(true,"sort");
        List<TrackDrawDO> trackDrawDOS = trackDrawYuLinService.selectList(wrapper);
        if (trackDrawDOS != null && !trackDrawDOS.isEmpty()) {
            List<TrackDrawJiangXiVO> trackDrawRegularVOS = new ArrayList<>();
            for (TrackDrawDO trackDrawDO : trackDrawDOS) {
                TrackDrawJiangXiVO trackDrawRegularVO = new TrackDrawJiangXiVO();
                BeanUtils.copyProperties(trackDrawDO,trackDrawRegularVO);
                trackDrawRegularVOS.add(trackDrawRegularVO);
            }
            //导出操作
            EasyPoiUtil.exportExcel(trackDrawRegularVOS, "模块A制定照护计划抽签信息导出", "模块A制定照护计划抽签信息导出", TrackDrawJiangXiVO.class,  "模块A制定照护计划抽签信息导出", response);
        } else {
            throw new IFastApiException(ApiEnumError.NOTBATCHSTU.getCodeStr());
        }
    }

	
}
